home *** CD-ROM | disk | FTP | other *** search
/ Openstep 4.2 (Developer) / Openstep Developer 4.2.iso / NextDeveloper / Source / GNU / perl / Perl / ext / SDBM_File / sdbm / sdbm.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-01  |  5.4 KB  |  235 lines

  1. /*
  2.  * sdbm - ndbm work-alike hashed database library
  3.  * based on Per-Ake Larson's Dynamic Hashing algorithms. BIT 18 (1978).
  4.  * author: oz@nexus.yorku.ca
  5.  * status: public domain. 
  6.  */
  7. #define DBLKSIZ 4096
  8. #define PBLKSIZ 1024
  9. #define PAIRMAX 1008            /* arbitrary on PBLKSIZ-N */
  10. #define SPLTMAX    10            /* maximum allowed splits */
  11.                     /* for a single insertion */
  12. #define DIRFEXT    ".dir"
  13. #define PAGFEXT    ".pag"
  14.  
  15. typedef struct {
  16.     int dirf;               /* directory file descriptor */
  17.     int pagf;               /* page file descriptor */
  18.     int flags;               /* status/error flags, see below */
  19.     long maxbno;               /* size of dirfile in bits */
  20.     long curbit;               /* current bit number */
  21.     long hmask;               /* current hash mask */
  22.     long blkptr;               /* current block for nextkey */
  23.     int keyptr;               /* current key for nextkey */
  24.     long blkno;               /* current page to read/write */
  25.     long pagbno;               /* current page in pagbuf */
  26.     char pagbuf[PBLKSIZ];           /* page file block buffer */
  27.     long dirbno;               /* current block in dirbuf */
  28.     char dirbuf[DBLKSIZ];           /* directory file block buffer */
  29. } DBM;
  30.  
  31. #define DBM_RDONLY    0x1           /* data base open read-only */
  32. #define DBM_IOERR    0x2           /* data base I/O error */
  33.  
  34. /*
  35.  * utility macros
  36.  */
  37. #define sdbm_rdonly(db)        ((db)->flags & DBM_RDONLY)
  38. #define sdbm_error(db)        ((db)->flags & DBM_IOERR)
  39.  
  40. #define sdbm_clearerr(db)    ((db)->flags &= ~DBM_IOERR)  /* ouch */
  41.  
  42. #define sdbm_dirfno(db)    ((db)->dirf)
  43. #define sdbm_pagfno(db)    ((db)->pagf)
  44.  
  45. typedef struct {
  46.     char *dptr;
  47.     int dsize;
  48. } datum;
  49.  
  50. extern datum nullitem;
  51.  
  52. #ifdef __STDC__
  53. #define proto(p) p
  54. #else
  55. #define proto(p) ()
  56. #endif
  57.  
  58. /*
  59.  * flags to sdbm_store
  60.  */
  61. #define DBM_INSERT    0
  62. #define DBM_REPLACE    1
  63.  
  64. /*
  65.  * ndbm interface
  66.  */
  67. extern DBM *sdbm_open proto((char *, int, int));
  68. extern void sdbm_close proto((DBM *));
  69. extern datum sdbm_fetch proto((DBM *, datum));
  70. extern int sdbm_delete proto((DBM *, datum));
  71. extern int sdbm_store proto((DBM *, datum, datum, int));
  72. extern datum sdbm_firstkey proto((DBM *));
  73. extern datum sdbm_nextkey proto((DBM *));
  74.  
  75. /*
  76.  * other
  77.  */
  78. extern DBM *sdbm_prep proto((char *, char *, int, int));
  79. extern long sdbm_hash proto((char *, int));
  80.  
  81. #ifndef SDBM_ONLY
  82. #define dbm_open sdbm_open;
  83. #define dbm_close sdbm_close;
  84. #define dbm_fetch sdbm_fetch;
  85. #define dbm_store sdbm_store;
  86. #define dbm_delete sdbm_delete;
  87. #define dbm_firstkey sdbm_firstkey;
  88. #define dbm_nextkey sdbm_nextkey;
  89. #define dbm_error sdbm_error;
  90. #define dbm_clearerr sdbm_clearerr;
  91. #endif
  92.  
  93. /* Most of the following is stolen from perl.h. */
  94. #ifndef H_PERL  /* Include guard */
  95.  
  96. /*
  97.  * The following contortions are brought to you on behalf of all the
  98.  * standards, semi-standards, de facto standards, not-so-de-facto standards
  99.  * of the world, as well as all the other botches anyone ever thought of.
  100.  * The basic theory is that if we work hard enough here, the rest of the
  101.  * code can be a lot prettier.  Well, so much for theory.  Sorry, Henry...
  102.  */
  103.  
  104. #include <errno.h>
  105. #ifdef HAS_SOCKET
  106. #   ifdef I_NET_ERRNO
  107. #     include <net/errno.h>
  108. #   endif
  109. #endif
  110.  
  111. #ifdef MYMALLOC
  112. #   ifdef HIDEMYMALLOC
  113. #    define malloc Mymalloc
  114. #    define realloc Myremalloc
  115. #    define free Myfree
  116. #   endif
  117. #   define safemalloc malloc
  118. #   define saferealloc realloc
  119. #   define safefree free
  120. #endif
  121.  
  122. #if defined(__STDC__) || defined(_AIX) || defined(__stdc__) || defined(__cplusplus)
  123. # define STANDARD_C 1
  124. #endif
  125.  
  126. #include <stdio.h>
  127. #include <ctype.h>
  128. #include <setjmp.h>
  129.  
  130. #ifdef I_UNISTD
  131. #include <unistd.h>
  132. #endif
  133.  
  134. #ifndef MSDOS
  135. #   ifdef PARAM_NEEDS_TYPES
  136. #    include <sys/types.h>
  137. #   endif
  138. #   include <sys/param.h>
  139. #endif
  140.  
  141. #ifndef _TYPES_        /* If types.h defines this it's easy. */
  142. #   ifndef major        /* Does everyone's types.h define this? */
  143. #    include <sys/types.h>
  144. #   endif
  145. #endif
  146.  
  147. #include <sys/stat.h>
  148.  
  149. #ifndef SEEK_SET
  150. # ifdef L_SET
  151. #  define SEEK_SET    L_SET
  152. # else
  153. #  define SEEK_SET    0  /* Wild guess. */
  154. # endif
  155. #endif
  156.  
  157. /* Use all the "standard" definitions? */
  158. #if defined(STANDARD_C) && defined(I_STDLIB)
  159. #   include <stdlib.h>
  160. #endif /* STANDARD_C */
  161.  
  162. #define MEM_SIZE Size_t
  163.  
  164. #ifdef I_STRING
  165. #include <string.h>
  166. #else
  167. #include <strings.h>
  168. #endif
  169.  
  170. #ifdef I_MEMORY
  171. #include <memory.h>
  172. #endif
  173.  
  174. #if defined(mips) && defined(ultrix) && !defined(__STDC__)
  175. #   undef HAS_MEMCMP
  176. #endif
  177.  
  178. #ifdef HAS_MEMCPY
  179. #  if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
  180. #    ifndef memcpy
  181.         extern char * memcpy _((char*, char*, int));
  182. #    endif
  183. #  endif
  184. #else
  185. #   ifndef memcpy
  186. #    ifdef HAS_BCOPY
  187. #        define memcpy(d,s,l) bcopy(s,d,l)
  188. #    else
  189. #        define memcpy(d,s,l) my_bcopy(s,d,l)
  190. #    endif
  191. #   endif
  192. #endif /* HAS_MEMCPY */
  193.  
  194. #ifdef HAS_MEMSET
  195. #  if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
  196. #    ifndef memset
  197.     extern char *memset _((char*, int, int));
  198. #    endif
  199. #  endif
  200. #  define memzero(d,l) memset(d,0,l)
  201. #else
  202. #   ifndef memzero
  203. #    ifdef HAS_BZERO
  204. #        define memzero(d,l) bzero(d,l)
  205. #    else
  206. #        define memzero(d,l) my_bzero(d,l)
  207. #    endif
  208. #   endif
  209. #endif /* HAS_MEMSET */
  210.  
  211. #ifdef HAS_MEMCMP
  212. #  if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
  213. #    ifndef memcmp
  214.     extern int memcmp _((char*, char*, int));
  215. #    endif
  216. #  endif
  217. #else
  218. #   ifndef memcmp
  219. #    define memcmp     my_memcmp
  220. #   endif
  221. #endif /* HAS_MEMCMP */
  222.  
  223. /* we prefer bcmp slightly for comparisons that don't care about ordering */
  224. #ifndef HAS_BCMP
  225. #   ifndef bcmp
  226. #    define bcmp(s1,s2,l) memcmp(s1,s2,l)
  227. #   endif
  228. #endif /* HAS_BCMP */
  229.  
  230. #ifdef I_NETINET_IN
  231. #   include <netinet/in.h>
  232. #endif
  233.  
  234. #endif /* Include guard */
  235.